<!-- 合同信息 -->
<template>
	<view>
		<view class="list_box" @touchstart="touchShow = false" @click="touchShow =false" @touchmove="touchShow = false">
			<view class="oyher_top">收款合同</view>
			<contarctCollectionItem :dataSource="collectionDataSource" @clickName="clickName" @clickNum="clickNum"></contarctCollectionItem>
			
			<view class="other_box"></view>
			<view class="oyher_top">付款合同</view>
			<contarctPaymentItem :dataSource="paymentDataSource"></contarctPaymentItem>
		</view>
	</view>
</template>

<script>
	import http from '@/utils/request/index.js'
	import specialHttp from '@/utils/request/specialIndex' // 特殊请求方式，直接返回res
	import address from '@/utils/address.js'
	import fileList from '@/pages/synergy/components/fileList.vue'
	import contarctCollectionItem from './contarctCollectionItem.vue'
	import contarctPaymentItem from './contarctPaymentItem.vue'
	export default {
		props: {
			projectId: {
				type: [String, Number],
				default: '',
			}
		},
		components: {
			fileList,
			contarctCollectionItem, // 收款合同
			contarctPaymentItem // 付款合同
		},
		watch: {
			projectId: {
				handler (val) {
					if (val) {
						this.loadDataByProjectId(val)	// 获取详情
					}
				},
				immediate: true
			}
		},
		data() {
			return {
				model: {},
				address,
				dataSource: [],
				collectionDataSource: [], // 收款
				paymentDataSource: [], // 付款
			}
		},
		methods: {
			
			// 获取投标信息
			async loadDataByProjectId(val) {
				await this.ininClearData();
				var params = await {
					projectId: val,
					column: 'createTime',
					order: 'desc',
					pageSize: 100,
					
				}
				http.get('/api/erp/project/report/erpProjectContractReport/list', params).then(async (res) => {
					if (res.success) {
						this.dataSource = await res.result.records;
						if (this.dataSource && this.dataSource.length) {
							// 收款合同
							this.collectionDataSource = this.dataSource.filter(item => {
								return item.contractType === '1'
							})
							// 时间降序排列
							if (this.collectionDataSource.length > 0) {
								this.collectionDataSource = this.collectionDataSource.sort((a, b) => new Date(a.createTime).getTime() - new Date(b.createTime).getTime()).reverse();
							}
							// 付款合同
							this.paymentDataSource = this.dataSource.filter(item => {
								return item.contractType === '2'
							})
							// 时间降序排列
							if (this.paymentDataSource.length > 0) {
								this.paymentDataSource = this.paymentDataSource.sort((a, b) => new Date(a.createTime).getTime() - new Date(b.createTime).getTime()).reverse();
							}
						}
					}
				})
			},
			ininClearData() {
				this.dataSource = []
			},
			
			// 点击收款合同名称
			clickName (item) {
				
			},
			// 点击收款合同变更记录次数
			clickNum (item) {
				
			}
		}
	}
</script>

<style lang="less" scoped>
@import url("@/assets/projectStyle.less");
</style>